package etcd

import (
	etcdClient "go.etcd.io/etcd/client/v3"
	"os"
	"time"
)

var DB *etcdClient.Client

func Install() error {
	mode := os.Getenv("MODE")

	point := "39.101.140.145:30014"
	if mode == "prod" {
		point = os.Getenv("ETCD_URL")
	}

	cli, err := etcdClient.New(etcdClient.Config{
		Endpoints:   []string{point},
		DialTimeout: time.Duration(5) * time.Second,
	})
	if err != nil {
		return err
	}
	DB = cli
	return nil
}
